package com.example.sunmiv1.dialog;

import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.sunmiv1.R;

import butterknife.BindView;
import butterknife.OnClick;

public class DeleteDialog extends BaseDialog {

    @BindView(R.id.orderSheet_remark_off)
    ImageView orderSheetRemarkOff;
    @BindView(R.id.orderSheet_remark_cancel)
    TextView orderSheetRemarkCancel;
    @BindView(R.id.orderSheet_remark_sure)
    TextView orderSheetRemarkSure;
    @BindView(R.id.deleteUser_title)
    TextView deleteUserTitle;

    private String title;

    public static DeleteDialog newInstance(String title) {
        DeleteDialog fragment = new DeleteDialog();
        Bundle bundle = new Bundle();
        bundle.putString("title", title);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_delete;
    }

    @Override
    protected void initView() {
        title = getArguments().getString("title");
        deleteUserTitle.setText(title);
    }

    @OnClick({R.id.orderSheet_remark_off, R.id.orderSheet_remark_cancel, R.id.orderSheet_remark_sure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.orderSheet_remark_off:
                dismiss();
                break;
            case R.id.orderSheet_remark_cancel:
                dismiss();
                break;
            case R.id.orderSheet_remark_sure:
                callback.success("");
                dismiss();
                break;
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();
        if (dialog != null) {
            // 下面這些設置必須在此方法(onStart())中才有效
            Window window = dialog.getWindow();
            // 如果不設置這句代碼, 那麼彈框就會與四邊都有一定的距離
            window.setBackgroundDrawableResource(android.R.color.transparent);
            window.setWindowAnimations(R.style.DialogFromBottom);// 設置動畫
            WindowManager.LayoutParams params = window.getAttributes();
            params.width = dp2px(350);
            window.setAttributes(setLayout(params));
        }
    }
}
